#include "EditorMaterialPreviewAbilityModel.h"

#include "EditorMaterialPreviewAbilityModel.h"

#include "Window/EditorWindowGroupModel.h"
#include "Material/Material.h"

void REditorMaterialPreviewAbilityModel::OnFocusedObjectChanged(TSharedObjectPtr<RObject> InObject)
{
    TSharedObjectPtr<RMaterial> NewMaterial;
    if(InObject&&InObject->IsA<RMaterial>())
    {
        NewMaterial=InObject;
    }
    else
    {
        NewMaterial=nullptr;
    }

    if(Material!=NewMaterial)
    {
        Material=NewMaterial;
        OnMaterialChanged.ExecuteIfBound();
    }
}

void REditorMaterialPreviewAbilityModel::FirstTimeInitializeObject()
{
    Super::FirstTimeInitializeObject();
 
    REditorWindowGroupModel::Get()->OnFocusedObjectChanged.BindScript(
        this
        ,&REditorMaterialPreviewAbilityModel::OnFocusedObjectChanged);

    OnFocusedObjectChanged(REditorWindowGroupModel::Get()->GetFocusedObject());  
}